<template>
  <el-drawer
    v-model="drawerVisible"
    :size="650"
    title="高级查询"
    @closed="$emit('closed')"
    append-to-body
  >
    <el-container v-loading="saveLoading">
      <el-main>
        <el-form
          :model="form"
          :rules="rules"
          ref="saveForm"
          label-width="140px"
        >
          <el-form-item label="跟进调查组" prop="followGroup">
            <hh-dict
              v-model="form.followGroup"
              dictType="investigation_team"
              placeholder="请选择跟进调查组"
              clearable
              filterable
            ></hh-dict>
          </el-form-item>

          <el-form-item label="填写时间范围" prop="fillingTime">
            <el-date-picker
              v-model="regDateScope"
              type="daterange"
              range-separator="至"
              start-placeholder="最早填写时间"
              end-placeholder="最晚填写时间"
              value-format="YYYY-MM-DD"
              :clearable="true"
            />
          </el-form-item>

          <el-form-item label="记录信息" prop="recordInformation">
            <el-input
              v-model="form.recordInformation"
              type="textarea"
              maxlength="500"
              :rows="15"
              placeholder="请输入记录信息"
              clearable
              show-word-limit
            ></el-input>
          </el-form-item>
        </el-form>
      </el-main>
      <el-footer>
        <div class="form-footer">
          <!-- <el-button type="" @click="close">取消</el-button> -->
          <el-button type="" @click="clear">清空查询条件</el-button>
          <el-button type="primary" @click="submit">查询</el-button>
        </div>
      </el-footer>
    </el-container>
  </el-drawer>
</template>

<script>
export default {
  name: "enterprise-filter",
  emits: ["success", "closed"],
  data() {
    return {
      drawerVisible: false,
      form: {
        followGroup: "",
        minFillingTime:"",
        maxFillingTime:"",
        recordInformation: "",
      },
      rules: {
        // roleName: [{ required: true, message: "请输入企业名称" }],
      },
      regDateScope:[]
    };
  },
  watch: {
    //日期范围转换
    regDateScope(val){
      if(val){
        this.form.minFillingTime = val[0]
        this.form.maxFillingTime = val[1]
      }else{
        this.form.minFillingTime = ""
        this.form.maxFillingTime = ""
      }
    }
    
  },
  mounted() {},
  methods: {
    //打开
    open(search) {
      this.drawerVisible = true;
      Object.assign(this.form, search);
      //日期范围转换
      if(this.form.minFillingTime && this.form.maxFillingTime){
        this.regDateScope[0] = this.form.minFillingTime
        this.regDateScope[1] = this.form.maxFillingTime
      }
    },
    //提交
    submit() {
      this.$refs.saveForm.validate(async (valid) => {
        if (valid) {
          this.$emit("onRefresh", this.form);
          this.close()
        }
      });
    },
    //表单注入数据
    clear() {
      let form = {
        followGroup: "",
        // fillingTime: "",
        minFillingTime:"",
        maxFillingTime:"",
        recordInformation: "",
      };
      this.regDateScope = []
      Object.assign(this.form, form);
    },
    // 关闭页面
    close() {
      this.$emit("closed");
    },
  },
};
</script>

<style></style>
